﻿

import Request from '../../base/request.js?t=202511041006'
import Storage from '../../base/storage.js?t=202511041006'
import { dealTime, queryURLParams, downloadfun, IgetDeptList, getRecentYears, getMonthList, getBrowserInfo, CONSTPARAMSDATA } from "../../base/utils.js?t=202511041006"
const Composition = (proxy) => {

    const generateh = (text, isShort) => {
        if (isShort) {
            return h('div', {
                style: "width:100px;overflow:hidden;white-space: nowrap;text-overflow: ellipsis; -o-text-overflow: ellipsis;cursor:pointer"
            }, { default: () => text })
        } else {
            return h('div', {
                style: "width:300px;height:auto;"
            }, { default: () => text })
        }

    }

    const data = reactive({
        messageTest: "",
        proxy: "",
        popTitle: "",
        cIndex: 1,
        tabList: [],
        queryParams: {
            Type: 1,
        },
        typelist: CONSTPARAMSDATA.typelist,
        planId: null,
        isAllPass: false,
        orecord: null,
        moduleList: [
            {
                label: "不可接受风险",
                value:"4bd914fa-3d01-11ef-8d56-fc3497c6d4e8"
            },
            {
                label: "重要环境因素",
                value:"60574236-3d01-11ef-8d56-fc3497c6d4e8"
            },
        ],
        urlinfo: {},
        Ids: [],
        sYearsList: [],
        plform: {

        },
        statusList: [],
        opType: true,
        popShow: false,
        pagination: {
            total: 0,
            current: 1,
            pageSize: 50,
            loading: true,
            showTotal: total => `总共 ${total} 项`,
            defaultPageSize: 10,
            showSizeChanger: true, // 是否显示pagesize选择
            showQuickJumper: false, // 是否显示跳转窗
        },

        deptList: [

        ],

        yearList: [

        ],
        monthList: [

        ],

        DepartmentTypeList: [],

        columns2: [
            {
                title: '序号',
                dataIndex: 'index',
                key: 'index',
                align: 'center',
                width: 80,
                customRender: ({ index }) => {
                    return (params.pagination.value.current - 1) * params.pagination.value.pageSize + index + 1
                },
            },
            {
                title: '部门',
                dataIndex: 'DepartmentName',
                key: 'DepartmentName',
                align: 'center'

            },
            {
                title: '危险源识别表',
                dataIndex: 'IOHS_Total',
                key: 'IOHS_Total',
                align: 'center',
                customRender: function ({ text, record, index, column }) {
                    let hdiv = (content) => h('div', {
                        style: `max-width: 600px;
                          `
                    }, {
                        default: () => content
                    })

                    const tag = (text, desc) => h(antd.Tag, {
                        color: "#108ee9",
                        style: desc ? "cursor:pointer" : "cursor:pointer"
                    }, { default: () => text })


                    const pop = (text, desc) => h(antd.Popover, {
                        title: '分级详情',
                        content: hdiv(desc),
                    }, () => [tag(text, desc)]);


                    return h('div', {
                        style: "display:flex;justify-content:center; width:auto; height:auto;margin:0 auto"
                    }, { default: () => [pop(text, `A级数量：${record.IOHS_Total_A}，B级数量：${record.IOHS_Total_B}，C级数量：${record.IOHS_Total_C}，D级数量：${record.IOHS_Total_D}`)] })
                },

            },

            {
                title: '新增',
                dataIndex: 'IOHS_Increase',
                key: 'IOHS_Increase',
                align: 'center',
                customRender: function ({ text, record, index, column }) {
                    let hdiv = (content) => h('div', {
                        style: `max-width: 600px;
                          `
                    }, {
                        default: () => content
                    })

                    const tag = (text, desc) => h(antd.Tag, {
                        color: "#108ee9",
                        style: desc ? "cursor:pointer" : "cursor:pointer"
                    }, { default: () => text })


                    const pop = (text, desc) => h(antd.Popover, {
                        title: '新增变动情况',
                        content: hdiv(desc),
                    }, () => [tag(text, desc)]);


                    return h('div', {
                        style: "display:flex;justify-content:center; width:auto; height:auto;margin:0 auto"
                    }, { default: () => [pop(text, record.IOHS_Increase_Des )] })
                },
              
            },
            {
                title: '删除',
                dataIndex: 'IOHS_Reduce',
                key: 'IOHS_Reduce',
                align: 'center',
                customRender: function ({ text, record, index, column }) {
                    let hdiv = (content) => h('div', {
                        style: `max-width: 600px;
                          `
                    }, {
                        default: () => content
                    })

                    const tag = (text, desc) => h(antd.Tag, {
                        color: "#108ee9",
                        style: desc ? "cursor:pointer" : "cursor:pointer"
                    }, { default: () => text })


                    const pop = (text, desc) => h(antd.Popover, {
                        title: '删除变动情况',
                        content: hdiv(desc),
                    }, () => [tag(text, desc)]);


                    return h('div', {
                        style: "display:flex;justify-content:center; width:50px; height:auto;margin:0 auto"
                    }, { default: () => [pop(text, record.IOHS_Reduce_Des)] })
                },
            },
            {
                title: '环境因素辨识表',
                dataIndex: 'EFI_Total',
                key: 'EFI_Total',
                align: 'center'

            },

            {
                title: '新增',
                dataIndex: 'EFI_Increase',
                key: 'EFI_Increase',
                align: 'center',
                customRender: function ({ text, record, index, column }) {
                    let hdiv = (content) => h('div', {
                        style: `max-width: 600px;
                          `
                    }, {
                        default: () => content
                    })

                    const tag = (text, desc) => h(antd.Tag, {
                        color: "#108ee9",
                        style: desc ? "cursor:pointer" : "cursor:pointer"
                    }, { default: () => text })


                    const pop = (text, desc) => h(antd.Popover, {
                        title: '新增变动情况',
                        content: hdiv(desc),
                    }, () => [tag(text, desc)]);


                    return h('div', {
                        style: "display:flex;justify-content:center; width:50px; height:auto;margin:0 auto"
                    }, { default: () => [pop(text, record.EFI_Increase_Des)] })
                },
            },
            {
                title: '删除',
                dataIndex: 'EFI_Reduce',
                key: 'EFI_Reduce',
                align: 'center',
                customRender: function ({ text, record, index, column }) {
                    let hdiv = (content) => h('div', {
                        style: `max-width: 600px;
                          `
                    }, {
                        default: () => content
                    })

                    const tag = (text, desc) => h(antd.Tag, {
                        color: "#108ee9",
                        style: desc ? "cursor:pointer" : "cursor:pointer"
                    }, { default: () => text })


                    const pop = (text, desc) => h(antd.Popover, {
                        title: '删除变动情况',
                        content: hdiv(desc),
                    }, () => [tag(text, desc)]);


                    return h('div', {
                        style: "display:flex;justify-content:center; width:50px; height:auto;margin:0 auto"
                    }, { default: () => [pop(text, record.EFI_Reduce_Des)] })
                },

            },
            {
                title: '不可接受风险',
                dataIndex: 'UR_Total',
                key: 'UR_Total',
                align: 'center',
                customRender: function ({ text, record, index, column }) {
                    let hdiv = (content) => h('div', {
                        style: `max-width: 600px;
                          `
                    }, {
                        default: () => content
                    })

                    const tag = (text, desc) => h(antd.Tag, {
                        color: "#108ee9",
                        style: desc ? "cursor:pointer" : "cursor:pointer"
                    }, { default: () => text })


                    const pop = (text, desc) => h(antd.Popover, {
                        title: '分级详情',
                        content: hdiv(desc),
                    }, () => [tag(text, desc)]);


                    return h('div', {
                        style: "display:flex;justify-content:center; width:auto; height:auto;margin:0 auto"
                    }, { default: () => [pop(text, `A级数量：${record.UR_Total_A}，B级数量：${record.UR_Total_B}，C级数量：${record.UR_Total_C}，D级数量：${record.UR_Total_D}`)] })
                },

            },

            {
                title: '新增',
                dataIndex: 'UR_Increase',
                key: 'UR_Increase',
                align: 'center',
                customRender: function ({ text, record, index, column }) {
                    let hdiv = (content) => h('div', {
                        style: `max-width: 600px;
                          `
                    }, {
                        default: () => content
                    })

                    const tag = (text, desc) => h(antd.Tag, {
                        color: "#108ee9",
                        style: desc ? "cursor:pointer" : "cursor:pointer"
                    }, { default: () => text })


                    const pop = (text, desc) => h(antd.Popover, {
                        title: '新增变动情况',
                        content: hdiv(desc),
                    }, () => [tag(text, desc)]);


                    return h('div', {
                        style: "display:flex;justify-content:center; width:50px; height:auto;margin:0 auto"
                    }, { default: () => [pop(text, record.UR_Increase_Des)] })
                },
            },
            {
                title: '删除',
                dataIndex: 'UR_Reduce',
                key: 'UR_Reduce',
                align: 'center',
                customRender: function ({ text, record, index, column }) {
                    let hdiv = (content) => h('div', {
                        style: `max-width: 600px;
                          `
                    }, {
                        default: () => content
                    })

                    const tag = (text, desc) => h(antd.Tag, {
                        color: "#108ee9",
                        style: desc ? "cursor:pointer" : "cursor:pointer"
                    }, { default: () => text })


                    const pop = (text, desc) => h(antd.Popover, {
                        title: '删除变动情况',
                        content: hdiv(desc),
                    }, () => [tag(text, desc)]);


                    return h('div', {
                        style: "display:flex;justify-content:center; width:50px; height:auto;margin:0 auto"
                    }, { default: () => [pop(text, record.UR_Reduce_Des)] })
                },

            },
            {
                title: '重要环境因素',
                dataIndex: 'HKEF_Total',
                key: 'HKEF_Total',
                align: 'center',
            },

            {
                title: '新增',
                dataIndex: 'HKEF_Increase',
                key: 'HKEF_Increase',
                align: 'center',
                customRender: function ({ text, record, index, column }) {
                    let hdiv = (content) => h('div', {
                        style: `max-width: 600px;
                          `
                    }, {
                        default: () => content
                    })

                    const tag = (text, desc) => h(antd.Tag, {
                        color: "#108ee9",
                        style: desc ? "cursor:pointer" : "cursor:pointer"
                    }, { default: () => text })


                    const pop = (text, desc) => h(antd.Popover, {
                        title: '新增变动情况',
                        content: hdiv(desc),
                    }, () => [tag(text, desc)]);


                    return h('div', {
                        style: "display:flex;justify-content:center; width:50px; height:auto;margin:0 auto"
                    }, { default: () => [pop(text, record.HKEF_Increase_Des)] })
                },
            },
            {
                title: '删除',
                dataIndex: 'HKEF_Reduce',
                key: 'HKEF_Reduce',
                align: 'center',
                customRender: function ({ text, record, index, column }) {
                    let hdiv = (content) => h('div', {
                        style: `max-width: 600px;
                          `
                    }, {
                        default: () => content
                    })

                    const tag = (text, desc) => h(antd.Tag, {
                        color: "#108ee9",
                        style: desc ? "cursor:pointer" : "cursor:pointer"
                    }, { default: () => text })


                    const pop = (text, desc) => h(antd.Popover, {
                        title: '删除变动情况',
                        content: hdiv(desc),
                    }, () => [tag(text, desc)]);


                    return h('div', {
                        style: "display:flex;justify-content:center; width:50px; height:auto;margin:0 auto"
                    }, { default: () => [pop(text, record.HKEF_Reduce_Des)] })
                },

            },
            //{
            //    title: '不可接受风险',
            //    dataIndex: 'DepartmentTypeName',
            //    key: 'DepartmentTypeName',
            //    align: 'center',
            //    width: '120px',
            //    customRender: function ({ text, record, index, column }) {

            //        let hdiv = (content) => h('div', {
            //            style: `width: 600px;
            //              `
            //        }, {
            //            default: () => content
            //        })


            //        const tag = (text, desc) => h(antd.Tag, {
            //            color: "#108ee9",
            //            style: desc ? "cursor:pointer" : ""
            //        }, { default: () => text })


            //        const pop = (text, desc) => h(antd.Popover, {
            //            title: '变动情况',
            //            content: hdiv(desc),
            //        }, () => [tag(text, desc)]);


            //        return h('div', {
            //            style: "display:flex;width:160px;height:auto;margin:0 auto"
            //        }, { default: () => [tag('总数:' + record.Total), pop('新增:' + record.IncreaseCount, record.IncreaseDescription), pop('删减:' + record.ReduceCount, record.ReduceDescription)] })
            //    },

            //},
  
        ],

        dataSource2: [],

        columns1: [
            {
                title: '序号',
                dataIndex: 'index',
                key: 'index',
                align: 'center',
                width: 80,
                customRender: ({ index }) => {
                    return (params.pagination.value.current - 1) * params.pagination.value.pageSize + index + 1
                },
            },
            {
                title: '部门',
                dataIndex: 'DepartmentName',
                key: 'DepartmentName',
                align: 'center'

            },
            {
                title: '标题',
                dataIndex: 'Title',
                key: 'Title',
                align: 'center'

            },
            
            {
                title: '业务',
                dataIndex: 'ModuleName',
                key: 'ModuleName',
                align: 'center'

            },
            {
                title: '总数',
                dataIndex: 'Total',
                key: 'Total',
                align: 'center',
                customRender: function ({ text, record, index, column }) {

                    let hdiv = (content) => h('div', {
                        style: `max-width: 600px;
                          `
                    }, {
                        default: () => content
                    })


                    const tag = (text, desc) => h(antd.Tag, {
                        color: "#108ee9",
                        style: desc ? "cursor:pointer" : ""
                    }, { default: () => text })


                    const pop = (text, desc) => h(antd.Popover, {
                        title: '分级情况',
                        content: hdiv(desc),
                    }, () => [tag(text, desc)]);


                    return h('div', {
                        style: "display:flex;width:120px;height:auto;margin:0 auto;justify-content: center;"
                    }, { default: () => [pop('总数:' + record.Total, `A级数量：${record.Total_A}，B级数量：${record.Total_B}，C级数量：${record.Total_C}，D级数量：${record.Total_D}`)] })
                },

            }, {
                title: '新增',
                dataIndex: 'IncreaseCount',
                key: 'IncreaseCount',
                align: 'center',
                customRender: function ({ text, record, index, column }) {
                    let hdiv = (content) => h('div', {
                        style: `max-width: 600px;
                          `
                    }, {
                        default: () => content
                    })

                    const tag = (text, desc) => h(antd.Tag, {
                        color: "#108ee9",
                        style: desc ? "cursor:pointer" : "cursor:pointer"
                    }, { default: () => text })


                    const pop = (text, desc) => h(antd.Popover, {
                        title: '新增变动情况',
                        content: hdiv(desc),
                    }, () => [tag(text, desc)]);


                    return h('div', {
                        style: "display:flex;justify-content:center; width:auto; height:auto;margin:0 auto"
                    }, { default: () => [pop(text, record.IncreaseDescription)] })
                },

            },
            {
                title: '删除',
                dataIndex: 'ReduceCount',
                key: 'ReduceCount',
                align: 'center',
                customRender: function ({ text, record, index, column }) {
                    let hdiv = (content) => h('div', {
                        style: `max-width: 600px;
                          `
                    }, {
                        default: () => content
                    })

                    const tag = (text, desc) => h(antd.Tag, {
                        color: "#108ee9",
                        style: desc ? "cursor:pointer" : "cursor:pointer"
                    }, { default: () => text })


                    const pop = (text, desc) => h(antd.Popover, {
                        title: '新增变动情况',
                        content: hdiv(desc),
                    }, () => [tag(text, desc)]);


                    return h('div', {
                        style: "display:flex;justify-content:center; width:auto; height:auto;margin:0 auto"
                    }, { default: () => [pop(text, record.ReduceDescription)] })
                },

            },
       
            {
                title: '类型',
                dataIndex: 'Title',
                key: 'Title',
                align: 'center',
                customRender: function ({text }) {
         
                    return h(antd.Tag, {
                        color: text == 2 ? '#108ee9' : '#003366'
                    }, () => text ? text == 2 ? '部门级' : '公司级' : '未知')
                }
            },
            {
                title: '日期',
                dataIndex: 'UpdateTime',
                key: 'UpdateTime',
                align: 'center',
                customRender: function ({ text }) {
                    return dealTime(text, 'YYYY-MM-DD HH:mm')
                }

            }

        ],

        dataSource1: [],

    })
    let params = toRefs(data)
    const methods = {
        tchange: (e) => {
            methods.getTableList(true)
            params.queryParams.value = {

            }
        },
        toAdd: (target) => {
            window.open(`/SafetySystem/IOHSADD?target=${target}`, "_self")
        },
        handleOk: () => {
            params.popShow.value = false

        },
        handleDetail: (item, name) => {
            window.open(`/SafetySystem/IOHSADD?target=${name + '|' + item.ModuleId}&id=${item.Id}&type=9`, "_self")

        },

        export_Data: () => {
            params.pagination.value.loading = true
            Request({
                url: "/SafetySystem/ExportDepartmentYearData",
                method: 'post',
                data: {
                    Years: params.queryParams.value.Years,
                    Type: params.queryParams.value.Type,
                    ModuleId: params.queryParams.value.module
                }
            }).then(res => {
                params.pagination.value.loading = false
                window.location.href =res.Data
               /* downloadfun(res.Data,'测试')*/
            })


        },
        handleEdit: (item, name) => {
            window.open(`/SafetySystem/IOHSADD?target=${name + '|' + item.ModuleId}&id=${item.Id}&type=1`, "_self")

        },
        handleDelete: (item, name) => {
            Request({
                url: "/SafetySystem/DeleteModuleForm",
                method: 'post',
                data: {
                    Id: item.Id
                }
            }).then(res => {
                params.messageTest.value.success(res.Msg);
                methods.getTableList(true)
            })

        },
        GetDepartmentList: async () => {
            let res = await IgetDeptList(Request)
            params.deptList.value = res
        },


        rowSelection: {
            onChange: (selectedRowKeys, selectedRows) => {

                params.Ids.value = selectedRowKeys

            },
            getCheckboxProps: record => ({
                disabled: record.Status != 3

            })
        },




        filterOption: (val, type) => {
            return `${type.label}`.includes(`${val || ''}`)
        },
        handleSearchChange: (page) => {

            methods.getTableList(true)
        },

        handleTableChange: (page) => {
            const { current, pageSize } = page
            params.pagination.value.current = current;
            params.pagination.value.pageSize = pageSize;
            methods.getTableList()
        },
        IGetSearchYearsList: () => {
            Request({
                url: "/SafetySystem/GetSearchYearsList",
                method: 'post',
                data: {
                    //ModuleId: params.urlinfo.value.module,
                }
            }).then(res => {
                params.sYearsList.value = res.Data.map(e => ({
                    label: e,
                    value: e
                }))

            })
        },
        getTableList: async (isRresh) => {
            if (isRresh) {
                params.pagination.value.current = 1
            }
            params.pagination.value.loading = true
            Request({
                url: "/SafetySystem/GetDepartmentYearData",
                method: 'post',
                params: {
                    page: params.pagination.value.current,
                    pageSize: params.pagination.value.pageSize
                },
                data: {
                    Years: params.queryParams.value.Years,
                    Type: params.queryParams.value.Type,
                    ModuleId: params.queryParams.value.module
                }
            }).then(res => {
                if (params.queryParams.value.Type == 1) {
                    params.dataSource2.value = res.Data
                    params.pagination.value.total = res.Data?.length
                    params.pagination.value.loading = false
                } else {
                    params.dataSource1.value = res.Data.Data
                    params.pagination.value.total = res.Data.Data?.length
                    params.pagination.value.loading = false
                }
           
            })

        },


        init: () => {

            getBrowserInfo().catch(err => { console.log(err) })
            if (proxy) {
                params.proxy.value = proxy
            }
            params.urlinfo.value = queryURLParams()
            params.yearList.value = getRecentYears()
            params.monthList.value = getMonthList()
            const { message } = antd
            params.messageTest.value = message
            params.messageTest.value.config({
                top: `10vh`,
                duration: 7,
                maxCount: 1,
                rtl: true,
            });
            params.queryParams.value.Years=dayjs().format('YYYY')
            setTimeout(() => {
                let info = Storage.get('AccountInfo', true)
                if (info && info.DepartmentId == 20) {
                    params.cIndex.value = 1
                    params.tabList.value = [{ label: "变动情况一览", value: 1 }]

                } else {
                    params.cIndex.value = 1
                    params.tabList.value = [{ label: "变动情况一览", value: 1 }]

                }

                Request({
                    url: "/Account/createJwtToken",
                    method: 'post',
                    data: {
                        "userName": info && info.UserNo
                    }
                }).then(async res => {
                    Storage.set('token', res.Data,true)
                    await methods.GetDepartmentList()
                    methods.getTableList(true)

                    methods.IGetSearchYearsList()


                })
            }, 400)

        },

    }



    const template = {
        test: {
            template: `<div @click="add">+</div> <div>{{testnum}}</div>`,

            setup() {

                return {
                    ...params,
                    ...methods,
                };
            }

        }
    }
    return {
        ...params,
        ...methods,
        template
    }
}

export default Composition